﻿using MOD_TaiYangQiu.config;
using MOD_TaiYangQiu.enums;
using MOD_TaiYangQiu.model;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static DataUnit;

namespace MOD_TaiYangQiu.common
{
    internal class CommonUtil
    {
        AptitudeSort aptitude = new AptitudeSort();
        /// <summary>
        /// 获取npc境界
        /// </summary>
        /// <param name="worldUnitData"></param>
        /// <returns></returns>
        public GradeLevel GetNpcGradeLevel(WorldUnitData worldUnitData)
        {
            string npcName = worldUnitData.unitData.propertyData.GetName();
            GradeLevel gradeLevel = new GradeLevel();
            int gradeId = worldUnitData.dynUnitData.gradeID.value;
            if (gradeId == 1)
            {
                gradeLevel = GradeLevel.LianQi_Q;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "练气前期"));
            }
            else if (gradeId == 2)
            {
                gradeLevel = GradeLevel.LianQi_Z;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "练气中期"));
            }
            else if (gradeId == 3)
            {
                gradeLevel = GradeLevel.LianQi_H;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "练气后期"));
            }
            else if (gradeId == 4 || gradeId == 5 || gradeId == 6)
            {
                gradeLevel = GradeLevel.ZhuJi_Q;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "筑基前期"));
            }
            else if (gradeId == 7)
            {
                gradeLevel = GradeLevel.ZhuJi_Z;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "筑基中期"));
            }
            else if (gradeId == 8)
            {
                gradeLevel = GradeLevel.ZhuJi_H;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "筑基后期"));
            }
            else if (gradeId == 9)
            {
                gradeLevel = GradeLevel.JieJing_Q;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "结晶前期"));
            }
            else if (gradeId == 10)
            {
                gradeLevel = GradeLevel.JieJing_Z;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "结晶中期"));
            }
            else if (gradeId == 11)
            {
                gradeLevel = GradeLevel.JieJing_H;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "结晶后期"));
            }
            else if (gradeId == 12 || gradeId == 13 || gradeId == 14 || gradeId == 15 || gradeId == 16)
            {
                gradeLevel = GradeLevel.JinDan_Q;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "金丹前期"));
            }
            else if (gradeId == 17)
            {
                gradeLevel = GradeLevel.JinDan_Z;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "金丹中期"));
            }
            else if (gradeId == 18)
            {
                gradeLevel = GradeLevel.JinDan_H;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "金丹后期"));
            }
            else if (gradeId == 19)
            {
                gradeLevel = GradeLevel.JuLing_Q;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "具灵前期"));
            }
            else if (gradeId == 20)
            {
                gradeLevel = GradeLevel.JuLing_Z;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "具灵中期"));
            }
            else if (gradeId == 21)
            {
                gradeLevel = GradeLevel.JuLing_H;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "具灵后期"));
            }
            else if (gradeId == 22 || gradeId == 23 || gradeId == 24)
            {
                gradeLevel = GradeLevel.YuanYing_Q;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "元婴前期"));
            }
            else if (gradeId == 25)
            {
                gradeLevel = GradeLevel.YuanYing_Z;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "元婴中期"));
            }
            else if (gradeId == 26)
            {
                gradeLevel = GradeLevel.YuanYing_H;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "元婴后期"));
            }
            else if (gradeId == 27)
            {
                gradeLevel = GradeLevel.HuaShen_Q;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "化神前期"));
            }
            else if (gradeId == 28)
            {
                gradeLevel = GradeLevel.HuaShen_Z;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "化神中期"));
            }
            else if (gradeId == 29)
            {
                gradeLevel = GradeLevel.HuaShen_H;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "化神后期"));
            }
            else if (gradeId == 30 || gradeId == 31 || gradeId == 32 || gradeId == 33)
            {
                gradeLevel = GradeLevel.WuDao_Q;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "悟道前期"));
            }
            else if (gradeId == 34)
            {
                gradeLevel = GradeLevel.WuDao_Z;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "悟道中期"));
            }
            else if (gradeId == 35)
            {
                gradeLevel = GradeLevel.WuDao_H;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "悟道后期"));
            }
            else if (gradeId == 36)
            {
                gradeLevel = GradeLevel.YuHua_Q;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "羽化前期"));
            }
            else if (gradeId == 37)
            {
                gradeLevel = GradeLevel.YuHua_Z;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "羽化中期"));
            }
            else if (gradeId == 38)
            {
                gradeLevel = GradeLevel.YuHua_H;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "羽化后期"));
            }
            else if (gradeId == 39 || gradeId == 40 || gradeId == 41 || gradeId == 42)
            {
                gradeLevel = GradeLevel.DengXian_Q;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "登仙前期"));
            }
            else if (gradeId == 43)
            {
                gradeLevel = GradeLevel.DengXian_Z;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "登仙前期"));
            }
            else if (gradeId == 44)
            {
                gradeLevel = GradeLevel.DengXian_H;
                LogUtil.Log("太阳球MOD", string.Format("[{0}]：{1}", npcName, "登仙前期"));
            }
            return gradeLevel;

        }

        /// <summary>
        /// 判断是否存在瓶颈运气
        /// </summary>
        /// <param name="unitNPC"></param>
        /// <returns></returns>
        public bool HasLockLuck(WorldUnitBase unitNPC)
        {
            bool isLock = false;
            Il2CppSystem.Collections.Generic.List<LuckData> lucks = unitNPC.data.unitData.propertyData.addLuck;
            string npcName = unitNPC.data.unitData.propertyData.GetName();
            foreach (LuckData luck in lucks)
            {
                if (BaseConfig.lockLuck.Contains(luck.id))
                {
                    return true;
                }
            }
            return isLock;
        }

        //判断人物是不是在宗门里
        public bool HasRelation(Il2CppSystem.Collections.Generic.List<string> wife, Il2CppSystem.Collections.Generic.List<string> couple, Il2CppSystem.Collections.Generic.List<string> teacher, Il2CppSystem.Collections.Generic.List<string> student, Il2CppSystem.Collections.Generic.List<string> parents, Il2CppSystem.Collections.Generic.List<string> children, Il2CppSystem.Collections.Generic.List<string> brother, string npcName)
        {
            if (parents.Contains(npcName))
            {
                LogUtil.Log("太阳球MOD", "【父母在宗门】");
                return false;
            }
            if (children.Contains(npcName))
            {
                LogUtil.Log("太阳球MOD", "【子女在宗门】");
                return false;
            }
            if (brother.Contains(npcName))
            {
                LogUtil.Log("太阳球MOD", "【兄弟姐妹在宗门】");
                return false;
            }
            if (wife.Contains(npcName))
            {
                LogUtil.Log("太阳球MOD", "【妻子在宗门】");
                return false;
            }
            if (couple.Contains(npcName))
            {
                LogUtil.Log("太阳球MOD", "【道侣在宗门】");
                return false;
            }
            if (teacher.Contains(npcName))
            {
                LogUtil.Log("太阳球MOD", "【师傅在宗门】");
                return false;
            }
            if (student.Contains(npcName))
            {
                LogUtil.Log("太阳球MOD", "【徒弟在宗门】");
                return false;
            }
            return true;
        }
        /// <summary>
        /// 获取资质顺序
        /// </summary>
        /// <param name="unitNPC"></param>
        /// <returns></returns>

        public List<NpcAptitude> GetNpcAptitudes(WorldUnitData unitNPC)
        {
            List<NpcAptitude> npcAptitudes = new List<NpcAptitude>();
            WorldUnitDynData dynData = unitNPC.dynUnitData;
            //刀
            NpcAptitude dao = new NpcAptitude();
            dao.Number = dynData.basisBlade.lastValue;
            dao.Aptitude = Aptitude.Dao;
            npcAptitudes.Add(dao);
            //枪
            NpcAptitude qiang = new NpcAptitude();
            qiang.Number = dynData.basisSpear.lastValue;
            qiang.Aptitude = Aptitude.Qiang;
            npcAptitudes.Add(qiang);
            //剑
            NpcAptitude jian = new NpcAptitude();
            jian.Number = dynData.basisSword.lastValue;
            jian.Aptitude = Aptitude.Jian;
            npcAptitudes.Add(jian);
            //拳
            NpcAptitude quan = new NpcAptitude();
            quan.Number = dynData.basisFist.lastValue;
            quan.Aptitude = Aptitude.Quan;
            npcAptitudes.Add(quan);
            //掌
            NpcAptitude zhang = new NpcAptitude();
            zhang.Number = dynData.basisPalm.lastValue;
            zhang.Aptitude = Aptitude.Zhang;
            npcAptitudes.Add(zhang);
            //指
            NpcAptitude zhi = new NpcAptitude();
            zhi.Number = dynData.basisFinger.lastValue;
            zhi.Aptitude = Aptitude.Zhi;
            npcAptitudes.Add(zhi);
            //火
            NpcAptitude huo = new NpcAptitude();
            huo.Number = dynData.basisFire.lastValue;
            huo.Aptitude = Aptitude.Huo;
            npcAptitudes.Add(huo);
            //水
            NpcAptitude shui = new NpcAptitude();
            shui.Number = dynData.basisFroze.lastValue;
            shui.Aptitude = Aptitude.Shui;
            npcAptitudes.Add(shui);
            //雷
            NpcAptitude lei = new NpcAptitude();
            lei.Number = dynData.basisThunder.lastValue;
            lei.Aptitude = Aptitude.Lei;
            npcAptitudes.Add(lei);
            //风
            NpcAptitude feng = new NpcAptitude();
            feng.Number = dynData.basisWind.lastValue;
            feng.Aptitude = Aptitude.Feng;
            npcAptitudes.Add(feng);
            //土
            NpcAptitude tu = new NpcAptitude();
            tu.Number = dynData.basisEarth.lastValue;
            tu.Aptitude = Aptitude.Tu;
            npcAptitudes.Add(tu);
            //木
            NpcAptitude mu = new NpcAptitude();
            mu.Number = dynData.basisWood.lastValue;
            mu.Aptitude = Aptitude.Mu;
            npcAptitudes.Add(mu);

            npcAptitudes.Sort(aptitude);
            //LogUtil.Log("太阳球MOD", "Npc资质：" + JsonConvert.SerializeObject(npcAptitudes));
            return npcAptitudes;

        }
        /// <summary>
        /// 获取最优功法
        /// </summary>
        /// <param name="oldDatas">积木空间道具</param>
        /// <param name="aptitude">npc资质</param>
        /// <param name="type">功法类型</param>
        /// <param name="gradeId">npc境界</param>
        /// <returns></returns>
        public Il2CppSystem.Collections.Generic.List<DataProps.PropsData> GetGoodMartial(Il2CppSystem.Collections.Generic.List<DataProps.PropsData> oldDatas, Aptitude aptitude, MartialType type, int gradeId)
        {
            Il2CppSystem.Collections.Generic.List<DataProps.PropsData> propsDatas = new Il2CppSystem.Collections.Generic.List<DataProps.PropsData>();
            //刀资质功法
            if (aptitude == Aptitude.Dao)
            {
                propsDatas = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                {
                    int martialType = e.values[3];
                    if (e.propsInfoBase.level == 6 && e.propsInfoBase.grade == gradeId && martialType == Convert.ToInt32(type))
                    {
                        ConfBattleSkillBaseItem baseItem = g.conf.data.battleSkillBase.GetItem(e.propsInfoBase.baseID);
                        int weaponType = baseItem.weaponType;
                        if (weaponType == Convert.ToInt32(BookMartial.Dao))
                        {
                            //判断功法类型
                            return true;
                        }
                        else
                        {
                            return false;
                        }

                    }
                    else
                    {
                        return false;
                    }
                }));
            }
            //枪资质功法
            else if (aptitude == Aptitude.Qiang)
            {
                propsDatas = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                {
                    int martialType = e.values[3];
                    if (e.propsInfoBase.level == 6 && e.propsInfoBase.grade == gradeId && martialType == Convert.ToInt32(type))
                    {
                        ConfBattleSkillBaseItem baseItem = g.conf.data.battleSkillBase.GetItem(e.propsInfoBase.baseID);
                        int weaponType = baseItem.weaponType;
                        if (weaponType == Convert.ToInt32(BookMartial.Qiang))
                        {
                            //判断功法类型
                            return true;
                        }
                        else
                        {
                            return false;
                        }

                    }
                    else
                    {
                        return false;
                    }
                }));
            }
            //剑资质功法
            else if (aptitude == Aptitude.Jian)
            {
                propsDatas = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                {
                    int martialType = e.values[3];
                    if (e.propsInfoBase.level == 6 && e.propsInfoBase.grade == gradeId && martialType == Convert.ToInt32(type))
                    {
                        ConfBattleSkillBaseItem baseItem = g.conf.data.battleSkillBase.GetItem(e.propsInfoBase.baseID);
                        int weaponType = baseItem.weaponType;
                        if (weaponType == Convert.ToInt32(BookMartial.Jian))
                        {
                            //判断功法类型
                            return true;
                        }
                        else
                        {
                            return false;
                        }

                    }
                    else
                    {
                        return false;
                    }
                }));
            }
            //拳资质功法
            else if (aptitude == Aptitude.Quan)
            {
                propsDatas = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                {
                    int martialType = e.values[3];
                    if (e.propsInfoBase.level == 6 && e.propsInfoBase.grade == gradeId && martialType == Convert.ToInt32(type))
                    {
                        ConfBattleSkillBaseItem baseItem = g.conf.data.battleSkillBase.GetItem(e.propsInfoBase.baseID);
                        int weaponType = baseItem.weaponType;
                        if (weaponType == Convert.ToInt32(BookMartial.Quan))
                        {
                            //判断功法类型
                            return true;
                        }
                        else
                        {
                            return false;
                        }

                    }
                    else
                    {
                        return false;
                    }
                }));
            }
            //掌资质功法
            else if (aptitude == Aptitude.Zhang)
            {
                propsDatas = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                {
                    int martialType = e.values[3];
                    if (e.propsInfoBase.level == 6 && e.propsInfoBase.grade == gradeId && martialType == Convert.ToInt32(type))
                    {
                        ConfBattleSkillBaseItem baseItem = g.conf.data.battleSkillBase.GetItem(e.propsInfoBase.baseID);
                        int weaponType = baseItem.weaponType;
                        if (weaponType == Convert.ToInt32(BookMartial.Zhang))
                        {
                            //判断功法类型
                            return true;
                        }
                        else
                        {
                            return false;
                        }

                    }
                    else
                    {
                        return false;
                    }
                }));
            }
            //指资质功法
            else if (aptitude == Aptitude.Zhi)
            {
                propsDatas = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                {
                    int martialType = e.values[3];
                    if (e.propsInfoBase.level == 6 && e.propsInfoBase.grade == gradeId && martialType == Convert.ToInt32(type))
                    {
                        ConfBattleSkillBaseItem baseItem = g.conf.data.battleSkillBase.GetItem(e.propsInfoBase.baseID);
                        int weaponType = baseItem.weaponType;
                        if (weaponType == Convert.ToInt32(BookMartial.Zhi))
                        {
                            //判断功法类型
                            return true;
                        }
                        else
                        {
                            return false;
                        }

                    }
                    else
                    {
                        return false;
                    }
                }));
            }
            //火资质功法
            else if (aptitude == Aptitude.Huo)
            {
                propsDatas = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                {
                    int martialType = e.values[3];
                    if (e.propsInfoBase.level == 6 && e.propsInfoBase.grade == gradeId && martialType == Convert.ToInt32(type))
                    {
                        ConfBattleSkillBaseItem baseItem = g.conf.data.battleSkillBase.GetItem(e.propsInfoBase.baseID);
                        int magicType = baseItem.magicType;
                        if (magicType == Convert.ToInt32(BookElement.Huo))
                        {
                            //判断功法类型
                            return true;
                        }
                        else
                        {
                            return false;
                        }

                    }
                    else
                    {
                        return false;
                    }
                }));
            }
            //水资质功法
            else if (aptitude == Aptitude.Shui)
            {
                propsDatas = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                {
                    int martialType = e.values[3];
                    if (e.propsInfoBase.level == 6 && e.propsInfoBase.grade == gradeId && martialType == Convert.ToInt32(type))
                    {
                        ConfBattleSkillBaseItem baseItem = g.conf.data.battleSkillBase.GetItem(e.propsInfoBase.baseID);
                        int magicType = baseItem.magicType;
                        if (magicType == Convert.ToInt32(BookElement.Shui))
                        {
                            //判断功法类型
                            return true;
                        }
                        else
                        {
                            return false;
                        }

                    }
                    else
                    {
                        return false;
                    }
                }));
            }
            //雷资质功法
            else if (aptitude == Aptitude.Lei)
            {
                propsDatas = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                {
                    int martialType = e.values[3];
                    if (e.propsInfoBase.level == 6 && e.propsInfoBase.grade == gradeId && martialType == Convert.ToInt32(type))
                    {
                        ConfBattleSkillBaseItem baseItem = g.conf.data.battleSkillBase.GetItem(e.propsInfoBase.baseID);
                        int magicType = baseItem.magicType;
                        if (magicType == Convert.ToInt32(BookElement.Lei))
                        {
                            //判断功法类型
                            return true;
                        }
                        else
                        {
                            return false;
                        }

                    }
                    else
                    {
                        return false;
                    }
                }));
            }
            //风资质功法
            else if (aptitude == Aptitude.Feng)
            {
                propsDatas = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                {
                    int martialType = e.values[3];
                    if (e.propsInfoBase.level == 6 && e.propsInfoBase.grade == gradeId && martialType == Convert.ToInt32(type))
                    {
                        ConfBattleSkillBaseItem baseItem = g.conf.data.battleSkillBase.GetItem(e.propsInfoBase.baseID);
                        int magicType = baseItem.magicType;
                        if (magicType == Convert.ToInt32(BookElement.Feng))
                        {
                            //判断功法类型
                            return true;
                        }
                        else
                        {
                            return false;
                        }

                    }
                    else
                    {
                        return false;
                    }
                }));
            }
            //土资质功法
            else if (aptitude == Aptitude.Tu)
            {
                propsDatas = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                {
                    int martialType = e.values[3];
                    if (e.propsInfoBase.level == 6 && e.propsInfoBase.grade == gradeId && martialType == Convert.ToInt32(type))
                    {
                        ConfBattleSkillBaseItem baseItem = g.conf.data.battleSkillBase.GetItem(e.propsInfoBase.baseID);
                        int magicType = baseItem.magicType;
                        if (magicType == Convert.ToInt32(BookElement.Tu))
                        {
                            //判断功法类型
                            return true;
                        }
                        else
                        {
                            return false;
                        }

                    }
                    else
                    {
                        return false;
                    }
                }));
            }
            //木资质功法
            else if (aptitude == Aptitude.Mu)
            {
                propsDatas = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                {
                    int martialType = e.values[3];
                    if (e.propsInfoBase.level == 6 && e.propsInfoBase.grade == gradeId && martialType == Convert.ToInt32(type))
                    {
                        ConfBattleSkillBaseItem baseItem = g.conf.data.battleSkillBase.GetItem(e.propsInfoBase.baseID);
                        int magicType = baseItem.magicType;
                        if (magicType == Convert.ToInt32(BookElement.Mu))
                        {
                            //判断功法类型
                            return true;
                        }
                        else
                        {
                            return false;
                        }

                    }
                    else
                    {
                        return false;
                    }
                }));
            }
            return propsDatas;
        }

        /// <summary>
        /// 获取最优心法
        /// </summary>
        /// <param name="oldDatas">积木空间道具</param>
        /// <param name="aptitude">npc资质</param>
        /// <param name="type">功法类型</param>
        /// <param name="gradeId">npc境界</param>
        /// <returns></returns>
        public Il2CppSystem.Collections.Generic.List<DataProps.PropsData> GetGoodMental(Il2CppSystem.Collections.Generic.List<DataProps.PropsData> oldDatas, Aptitude aptitude, MartialType type, int gradeId, int heardBookType)
        {
            Il2CppSystem.Collections.Generic.List<DataProps.PropsData> propsDatas = new Il2CppSystem.Collections.Generic.List<DataProps.PropsData>();
            if (aptitude == Aptitude.None)
            {

            }
            else
            {
                //刀资质功法
                if (aptitude == Aptitude.Dao)
                {
                    propsDatas = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                    {
                        int martialType = e.values[3];
                        if (e.propsInfoBase.level == 6 && e.propsInfoBase.grade == gradeId && martialType == Convert.ToInt32(type))
                        {
                            ConfBattleAbilityBaseItem baseItem = g.conf.data.battleAbilityBase.GetItem(e.propsInfoBase.baseID);
                            string heartType = baseItem.basType;
                            if (heardBookType < 6)
                            {
                                if (heartType == "basAllAny" && heardBookType == baseItem.type)
                                {
                                    //判断功法类型
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                            else
                            {
                                if (heartType == "basBlade" && heardBookType == baseItem.type)
                                {
                                    //判断功法类型
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }

                        }
                        else
                        {
                            return false;
                        }
                    }));
                }
                //枪资质功法
                else if (aptitude == Aptitude.Qiang)
                {
                    propsDatas = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                    {
                        int martialType = e.values[3];
                        if (e.propsInfoBase.level == 6 && e.propsInfoBase.grade == gradeId && martialType == Convert.ToInt32(type))
                        {
                            ConfBattleAbilityBaseItem baseItem = g.conf.data.battleAbilityBase.GetItem(e.propsInfoBase.baseID);
                            string heartType = baseItem.basType;
                            if (heardBookType < 6)
                            {
                                if (heartType == "basAllAny" && heardBookType == baseItem.type)
                                {
                                    //判断功法类型
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                            else
                            {
                                if (heartType == "basSpear" && heardBookType == baseItem.type)
                                {
                                    //判断功法类型
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }));
                }
                //剑资质功法
                else if (aptitude == Aptitude.Jian)
                {
                    propsDatas = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                    {
                        int martialType = e.values[3];
                        if (e.propsInfoBase.level == 6 && e.propsInfoBase.grade == gradeId && martialType == Convert.ToInt32(type))
                        {
                            ConfBattleAbilityBaseItem baseItem = g.conf.data.battleAbilityBase.GetItem(e.propsInfoBase.baseID);
                            string heartType = baseItem.basType;
                            if (heardBookType < 6)
                            {
                                if (heartType == "basAllAny" && heardBookType == baseItem.type)
                                {
                                    //判断功法类型
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                            else
                            {
                                if (heartType == "basSword" && heardBookType == baseItem.type)
                                {
                                    //判断功法类型
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }));
                }
                //拳资质功法
                else if (aptitude == Aptitude.Quan)
                {
                    propsDatas = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                    {
                        int martialType = e.values[3];
                        if (e.propsInfoBase.level == 6 && e.propsInfoBase.grade == gradeId && martialType == Convert.ToInt32(type))
                        {
                            ConfBattleAbilityBaseItem baseItem = g.conf.data.battleAbilityBase.GetItem(e.propsInfoBase.baseID);
                            string heartType = baseItem.basType;
                            if (heardBookType < 6)
                            {
                                if (heartType == "basAllAny" && heardBookType == baseItem.type)
                                {
                                    //判断功法类型
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                            else
                            {
                                if (heartType == "basFist" && heardBookType == baseItem.type)
                                {
                                    //判断功法类型
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }));
                }
                //掌资质功法
                else if (aptitude == Aptitude.Zhang)
                {
                    propsDatas = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                    {
                        int martialType = e.values[3];
                        if (e.propsInfoBase.level == 6 && e.propsInfoBase.grade == gradeId && martialType == Convert.ToInt32(type))
                        {
                            ConfBattleAbilityBaseItem baseItem = g.conf.data.battleAbilityBase.GetItem(e.propsInfoBase.baseID);
                            string heartType = baseItem.basType;
                            if (heardBookType < 6)
                            {
                                if (heartType == "basAllAny" && heardBookType == baseItem.type)
                                {
                                    //判断功法类型
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                            else
                            {
                                if (heartType == "basPalm" && heardBookType == baseItem.type)
                                {
                                    //判断功法类型
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }));
                }
                //指资质功法
                else if (aptitude == Aptitude.Zhi)
                {
                    propsDatas = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                    {
                        int martialType = e.values[3];
                        if (e.propsInfoBase.level == 6 && e.propsInfoBase.grade == gradeId && martialType == Convert.ToInt32(type))
                        {
                            ConfBattleAbilityBaseItem baseItem = g.conf.data.battleAbilityBase.GetItem(e.propsInfoBase.baseID);
                            string heartType = baseItem.basType;
                            if (heardBookType < 6)
                            {
                                if (heartType == "basAllAny" && heardBookType == baseItem.type)
                                {
                                    //判断功法类型
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                            else
                            {
                                if (heartType == "basFinger" && heardBookType == baseItem.type)
                                {
                                    //判断功法类型
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }));
                }
                //火资质功法
                else if (aptitude == Aptitude.Huo)
                {
                    propsDatas = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                    {
                        int martialType = e.values[3];
                        if (e.propsInfoBase.level == 6 && e.propsInfoBase.grade == gradeId && martialType == Convert.ToInt32(type))
                        {
                            ConfBattleAbilityBaseItem baseItem = g.conf.data.battleAbilityBase.GetItem(e.propsInfoBase.baseID);
                            string heartType = baseItem.basType;
                            if (heardBookType < 6)
                            {
                                if (heartType == "basAllAny" && heardBookType == baseItem.type)
                                {
                                    //判断功法类型
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                            else
                            {
                                if (heartType == "basFire" && heardBookType == baseItem.type)
                                {
                                    //判断功法类型
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }));
                }
                //水资质功法
                else if (aptitude == Aptitude.Shui)
                {
                    propsDatas = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                    {
                        int martialType = e.values[3];
                        if (e.propsInfoBase.level == 6 && e.propsInfoBase.grade == gradeId && martialType == Convert.ToInt32(type))
                        {
                            ConfBattleAbilityBaseItem baseItem = g.conf.data.battleAbilityBase.GetItem(e.propsInfoBase.baseID);
                            string heartType = baseItem.basType;
                            if (heardBookType < 6)
                            {
                                if (heartType == "basAllAny" && heardBookType == baseItem.type)
                                {
                                    //判断功法类型
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                            else
                            {
                                if (heartType == "basFroze" && heardBookType == baseItem.type)
                                {
                                    //判断功法类型
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }));
                }
                //雷资质功法
                else if (aptitude == Aptitude.Lei)
                {
                    propsDatas = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                    {
                        int martialType = e.values[3];
                        if (e.propsInfoBase.level == 6 && e.propsInfoBase.grade == gradeId && martialType == Convert.ToInt32(type))
                        {
                            ConfBattleAbilityBaseItem baseItem = g.conf.data.battleAbilityBase.GetItem(e.propsInfoBase.baseID);
                            string heartType = baseItem.basType;
                            if (heardBookType < 6)
                            {
                                if (heartType == "basAllAny" && heardBookType == baseItem.type)
                                {
                                    //判断功法类型
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                            else
                            {
                                if (heartType == "basThunder" && heardBookType == baseItem.type)
                                {
                                    //判断功法类型
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }));
                }
                //风资质功法
                else if (aptitude == Aptitude.Feng)
                {
                    propsDatas = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                    {
                        int martialType = e.values[3];
                        if (e.propsInfoBase.level == 6 && e.propsInfoBase.grade == gradeId && martialType == Convert.ToInt32(type))
                        {
                            ConfBattleAbilityBaseItem baseItem = g.conf.data.battleAbilityBase.GetItem(e.propsInfoBase.baseID);
                            string heartType = baseItem.basType;
                            if (heardBookType < 6)
                            {
                                if (heartType == "basAllAny" && heardBookType == baseItem.type)
                                {
                                    //判断功法类型
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                            else
                            {
                                if (heartType == "basWind" && heardBookType == baseItem.type)
                                {
                                    //判断功法类型
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }));
                }
                //土资质功法
                else if (aptitude == Aptitude.Tu)
                {
                    propsDatas = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                    {
                        int martialType = e.values[3];
                        if (e.propsInfoBase.level == 6 && e.propsInfoBase.grade == gradeId && martialType == Convert.ToInt32(type))
                        {
                            ConfBattleAbilityBaseItem baseItem = g.conf.data.battleAbilityBase.GetItem(e.propsInfoBase.baseID);
                            string heartType = baseItem.basType;
                            if (heardBookType < 6)
                            {
                                if (heartType == "basAllAny" && heardBookType == baseItem.type)
                                {
                                    //判断功法类型
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                            else
                            {
                                if (heartType == "basEarth" && heardBookType == baseItem.type)
                                {
                                    //判断功法类型
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }));
                }
                //木资质功法
                else if (aptitude == Aptitude.Mu)
                {
                    propsDatas = oldDatas.FindAll(new Func<DataProps.PropsData, bool>((e) =>
                    {
                        int martialType = e.values[3];
                        if (e.propsInfoBase.level == 6 && e.propsInfoBase.grade == gradeId && martialType == Convert.ToInt32(type))
                        {
                            ConfBattleAbilityBaseItem baseItem = g.conf.data.battleAbilityBase.GetItem(e.propsInfoBase.baseID);
                            string heartType = baseItem.basType;
                            if (heardBookType < 6)
                            {
                                if (heartType == "basAllAny" && heardBookType == baseItem.type)
                                {
                                    //判断功法类型
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                            else
                            {
                                if (heartType == "basWood" && heardBookType == baseItem.type)
                                {
                                    //判断功法类型
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }));
                }
            }

            return propsDatas;
        }

        /// <summary>
        /// 获取积木空间道具
        /// </summary>
        /// <returns></returns>
        public Il2CppSystem.Collections.Generic.List<DataProps.PropsData> GetTownStorage()
        {
            Il2CppSystem.Collections.Generic.List<DataProps.PropsData> propsDatas = new Il2CppSystem.Collections.Generic.List<DataProps.PropsData>();
            Il2CppSystem.Collections.Generic.List<MapBuildBase> GetBuilds = g.world.build.GetBuilds(MapTerrainType.Town);
            if (GetBuilds.Count < BaseConfig.storageIndex)
            {
                return propsDatas;
            }
            //版本更新之后数据索引由0变成1
            MapBuildBase buildBase = GetBuilds[BaseConfig.storageIndex];
            MapBuildSubBase mapBuild = buildBase.GetBuildSub(MapBuildSubType.TownStorage);
            string baseData = mapBuild.buildData.objData.GetString("data");
            //LogUtil.Log("太阳球MOD", baseData);
            if (baseData == null || baseData.Replace(" ", "") == "")
            {
                return propsDatas;
            }
            JObject baseDataObj = JObject.Parse(baseData);
            string propData = baseDataObj["propData"].ToString();
            JObject propDataObj = JObject.Parse(propData);
            string allProps = propDataObj["allProps"].ToString();
            //获取积木道具集合
            JArray itemDataList = JArray.Parse(allProps);
            foreach (JObject itemData in itemDataList)
            {
                string soleId = itemData["q"].ToString();//编号
                string valuesSting = itemData["w"].ToString();//数据值
                int[] values = JsonConvert.DeserializeObject<int[]>(valuesSting);
                //长度大于4
                if (values.Length > 4)
                {
                    //武学秘籍
                    if (values[0] == 2)
                    {
                        //秘籍类型
                        if (values[3] == Convert.ToInt32(MartialType.SkillLeft))
                        {
                            int[] addValues = new int[values.Length - 4];
                            Array.Copy(values, 4, addValues, 0, values.Length - 4);
                            DataProps.PropsData propsData = DataProps.PropsData.NewMartial(MartialType.SkillLeft, addValues);
                            //LogUtil.Log("太阳球MOD", propsData.propsInfoBase.name);
                            propsDatas.Add(propsData);
                        }
                        else if (values[3] == Convert.ToInt32(MartialType.SkillRight))
                        {
                            int[] addValues = new int[values.Length - 4];
                            Array.Copy(values, 4, addValues, 0, values.Length - 4);
                            DataProps.PropsData propsData = DataProps.PropsData.NewMartial(MartialType.SkillRight, addValues);
                            //LogUtil.Log("太阳球MOD", propsData.propsInfoBase.name);
                            propsDatas.Add(propsData);
                        }
                        else if (values[3] == Convert.ToInt32(MartialType.Step))
                        {
                            int[] addValues = new int[values.Length - 4];
                            Array.Copy(values, 4, addValues, 0, values.Length - 4);
                            DataProps.PropsData propsData = DataProps.PropsData.NewMartial(MartialType.Step, addValues);
                            //LogUtil.Log("太阳球MOD", propsData.propsInfoBase.name);
                            propsDatas.Add(propsData);
                        }
                        else if (values[3] == Convert.ToInt32(MartialType.Ability))
                        {
                            int[] addValues = new int[values.Length - 4];
                            Array.Copy(values, 4, addValues, 0, values.Length - 4);
                            DataProps.PropsData propsData = DataProps.PropsData.NewMartial(MartialType.Ability, addValues);
                            //LogUtil.Log("太阳球MOD", propsData.propsInfoBase.name);
                            propsDatas.Add(propsData);
                        }
                        else if (values[3] == Convert.ToInt32(MartialType.Ultimate))
                        {
                            int[] addValues = new int[values.Length - 4];
                            Array.Copy(values, 4, addValues, 0, values.Length - 4);
                            DataProps.PropsData propsData = DataProps.PropsData.NewMartial(MartialType.Ultimate, addValues);
                            //LogUtil.Log("太阳球MOD", propsData.propsInfoBase.name);
                            propsDatas.Add(propsData);
                        }
                    }
                }
            }
            return propsDatas;

        }

        Random random = new Random();
        /// <summary>
        /// 获取随机数
        /// </summary>
        /// <returns></returns>

        public int getRandomBetween(AptitudeData aptitudeData)
        {
            int result = aptitudeData.Other;
            if (aptitudeData.Random)
            {
                result = random.Next(aptitudeData.Other, aptitudeData.Host);
            }
            return result;
        }


    }
}
